using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;

public class GameManager : Singleton<GameManager>
{
    public CharacterStats playerStat;
    public List<IEndGameObserver> endGameObservers = new List<IEndGameObserver>();
    public CinemachineFreeLook followCamera;
    protected override void Awake()
    {
        base.Awake();
        DontDestroyOnLoad(this);
    }
    public void AddEndGameObservers(IEndGameObserver ob)
    {
        endGameObservers.Add(ob);
    }
    public void RemoveEndGameObservers(IEndGameObserver ob)
    {
        endGameObservers.Remove(ob);
    }
    public void RegisterPlayer(CharacterStats stat)
    {
        playerStat = stat;
        // 设置相机跟随
        followCamera = FindObjectOfType<CinemachineFreeLook>();
        if (followCamera != null)
        {
            followCamera.Follow = playerStat.transform.GetChild(2);
            followCamera.LookAt = playerStat.transform.GetChild(2);
        }
    }
    public void NotifyObservers()
    {
        foreach (var ob in endGameObservers)
        {
            ob.EndNotify();
        }
    }
    public Transform GetEntrance()
    {
        var entrances = FindObjectsOfType<TransitionDestination>();
        foreach (var e in entrances)
        {
            if (e.destinationTag == DestinationTag.Enter)
            {
                return e.transform;
            }
        }
        return null;
    }
}
